<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta content="user-scalable=no, width=device-width, initial-scale=1.0, maximum-scale=1.0" name="viewport">
<script language="javascript" src="__PUBLIC__/Home/js/jquery-2.1.1.min.js"></script>
<link href="__PUBLIC__/Home/login_css/login.css" rel="stylesheet"/>
<title>登录</title>
</head>

<body>
<form action="{:U('Api/ApiUser/login')}" id="form" method="post">
    <input class="form-control"  id="platform" name="platform" type="hidden" value="{$platform}">
    <input class="form-control" name="url" type="hidden" value="{$website}">
<div class="login-body">
<div class="qiezi_logo"><img width="135px;" src="__PUBLIC__/Home/img/logo.png" /></div>
<div class="login_con">
<ul>
<li class="input_phone"><input type="number" placeholder="手机号码" name="mobile" id="mobile" class="phone_num" /></li>
<li class="input_code"><input type="number" placeholder="动态密码"  name="code" id="code" class="password_num" /><input type="button"  value="获取密码" onclick="send_code();" class="psw_btn"/><div class="clear"></div></li>
</ul>
</div>
<div class="login_submit" id="login">登录</div>
</div>
</form>
<script type="text/javascript">
    $(document).ready(function(){
        $("#login").click(function(){  
           // $("#form").submit();  
            $.ajax({

                type: "POST",
                url:"doPhoneLogin",
                data:$("#form").serialize(),// 你的formid
                async: false,
                success: function(data) {

                    if(data.state==-1) {
                        //账号错误 或 密码错误
                        alert(data.msg);
                    }else{

                        window.location.href= data.msg;
                    }
                }
            });
        });
    });


var isGetCodeing = false;
function send_code()
{
    var tel = $(".phone_num").val();
    var reg = /^1[3|4|5|7|8][0-9]\d{4,8}$/;
    if(!reg.test(tel)){
        alert("请输入正确的手机号！");
        return false;
    }
    if(isGetCodeing) return;
    isGetCodeing = true;
    $.post("{:U('Api/ApiUser/ajaxGetCode')}",{mobile:tel},function(data){


        if(data != ''){
            var code = data.code;
            var msg = data.msg;
            if(code < 0){
                alert(msg);
            }else{
                count_down();
            }
        }else{
            isGetCodeing = false;
            alert('发送失败');

        }
    });

}

var wait = 60;
function count_down(){
    if(wait <= 0){
        isGetCodeing = false;
        $(".psw_btn").removeAttr("disabled");
        $(".psw_btn").val("获取验证码");
        wait = 60;
    }else{
        $(".psw_btn").attr("disabled", true);
        $(".psw_btn").val("剩余" + wait + "秒");
        wait--;
        setTimeout("count_down()", 1000);
    }
}
</script>
</body>
</html>
